<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="https://code.jquery.com/jquery-3.3.1.min.js"></script>
    <style>
        *{
            margin: 0;
            padding: 0;
        }
        body{
            width: 100%;
            height: 100%;
            text-align: center;
            background-color: darkorchid;
        }
        button{
            margin-top: 300px;
            background-color: #BA55D3;
        }
        button:hover{
            cursor: pointer;
        }
    </style>
</head>

<body>
    <button onclick="changeBackground()">修改背景颜色</button>
</body>
<script>
    //改变界面的背景颜色随机
    const changeBackground = () => {
        let bdy = ['red','darkorchid','yellow','green','greenyellow','pink','orange'];
        let btn = ['#CD5C5C','#BA55D3','#FFD700','#00FF00','#7CFC00','#FF69B4','#FF8C00'];
        let num = randomNum(bdy.length);
        $("body").css('background-color',bdy[num]);
        $("button").css('background-color',btn[num])
    }

    //获取随机数
    const randomNum = num =>{
        return Math.floor(Math.random()*num);
    }
    
</script>
</html>